//
//  ViewController.m
//  GCD常用函数
//
//  Created by 李煜 on 2024/3/20.
//

#import "ViewController.h"
#import "XMOperation.h"
@interface ViewController ()
@property (nonatomic,strong) NSOperationQueue *queue;
@end

@implementation ViewController

-(void)viewDidLoad {
	[super viewDidLoad];
	
	
	
}
- (IBAction)start:(id)sender {
	NSOperationQueue *queue1 = [[NSOperationQueue alloc]init];
	//设置最大并发数=1,线程同步(同一时间只能执行一个任务)
	//默认=-1,表示不限制
	//>1则开线程
	queue1.maxConcurrentOperationCount = 1;
	self.queue = queue1;
	
	XMOperation *op1= [[XMOperation alloc]init];
	XMOperation *op2= [[XMOperation alloc]init];
	XMOperation *op3= [[XMOperation alloc]init];
	XMOperation *op4= [[XMOperation alloc]init];
	
		//队列1添加op1 op2 op3
	[queue1 addOperation:op1];
	[queue1 addOperation:op2];
	[queue1 addOperation:op3];
	[queue1 addOperation:op4];
	
}
- (IBAction)suspend:(id)sender {
	self.queue.suspended = YES;
}
- (IBAction)resume:(id)sender {
	self.queue.suspended = NO;
}
- (IBAction)cancel:(id)sender {
	[self.queue cancelAllOperations];
}

@end
